package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IProductService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.*;
import com.mall.user.annotation.Anoymous;
import com.mall.user.constants.SysRetCodeConstants;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * @author 姚旭佳
 */
@RestController
@RequestMapping("/shopping")
public class ProductController {
    @Reference(timeout = 3000, retries = 0, check = false)
    IProductService productService;



    @GetMapping("/product/{id}")
    @Anoymous
    public ResponseData getProductDetail(@PathVariable("id") Long productId) {

        ProductDetailRequest request = new ProductDetailRequest();
        request.setId(productId);

        ProductDetailResponse productDetail = productService.getProductDetail(request);
        if (ShoppingRetCode.SUCCESS.getCode().equals(productDetail.getCode())) {
            return new ResponseUtil().setData(productDetail.getProductDetailDto());
        }

        return new ResponseUtil().setErrorMsg(productDetail.getMsg());
    }
    @RequestMapping("/goods")
    @Anoymous
    public  ResponseData getAllProduct(AllProductRequest request){

        AllProductResponse allProduct = productService.getAllProduct(request);
        if (ShoppingRetCode.SUCCESS.getCode().equals(allProduct.getCode())) {
            allProduct.setCode(null);
            allProduct.setMsg(null);
            return new ResponseUtil().setData(allProduct);
        }

        return new ResponseUtil().setErrorMsg(allProduct.getMsg());
    }



    /**
     * lxy
     * @return
     */
    @Anoymous
    @GetMapping("/recommend")
    public ResponseData recommend() {
        RecommendResponse response = productService.getRecommendGoods();
        if (response.getCode().equals(ShoppingRetCode.SUCCESS.getCode())) {
            return new ResponseUtil().setData(response.getPanelContentItemDtos());
        }
        return new ResponseUtil().setErrorMsg(response.getMsg());
    }
}
